package com.example.attempt.service.impl;

import com.example.attempt.entity.Submit;
import com.example.attempt.mapper.SubmitMapper;
import com.example.attempt.service.SubmitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SubmitServiceImpl implements SubmitService {
    @Autowired
    SubmitMapper submitMapper;
    @Override
    public int addSubmit(Submit submit) {
        submitMapper.addSubmit(submit);
        return 0;
    }

    @Override
    public Submit queryBySubId(int submitId) {
        return submitMapper.queryBySubId(submitId);
    }

    @Override
    public Submit queryBySidAndHid(int hid, String sid) {
        List<Submit> submits=submitMapper.queryByHid(hid);
        Submit submit;
        for (int i=0;i<submits.size();i++){
            submit=submits.get(i);
            if(submit.getSid().equals(sid)){
                return submit;
            }
        }
        return null;
    }

    @Override
    public List<Integer> getSubIdByHid(int hid) {
        return submitMapper.getSubIdByHid(hid);
    }

    @Override
    public int getSubmitNumber(int hid) {
        System.out.println(submitMapper.getSubIdByHid(hid).toString());
        return submitMapper.getSubIdByHid(hid).size();
    }

    @Override
    public List<Submit> getByHid(int hid) {
        return submitMapper.queryByHid(hid);
    }

    @Override
    public List<Submit> getHighSubmit(double threshold){
        return submitMapper.getHighSubmit(threshold);
    }

    @Override
    public int deleteSubmit(int submitId) {
        submitMapper.deleteSubmit(submitId);
        return 0;
    }
    @Override
    public int updateSimilarity(int submitId, double simi){
        return submitMapper.updateSimilarity(submitId, simi);
    }

    @Override
    public List<Integer> queryBySid(String sid){
        return submitMapper.queryBySid(sid);
    }
    @Override
    public int updateLink(int submitid,String link){
        return submitMapper.updateLink(submitid,link);
    }
}
